include("shared.lua")

local MODEL = Model( "models/props_c17/light_cagelight02_on.mdl" )


/*---------------------------------------------------------
   Name: Initialize
---------------------------------------------------------*/
function ENT:Initialize()

	//TODO: fix index's
	local backLight = {}
	backLight.Angle = 120
	backLight.Color = Color(253,233,174,255)
	backLight.Radius = 100.0
	backLight.Brightness = 10
	backLight.Size = 100
	backLight.Index = 1

	local keyLight = {}
	keyLight.Angle = 240
	keyLight.Color = Color(236,220,205,255)
	keyLight.Radius = 100.0
	keyLight.Brightness = 10
	keyLight.Size = 100
	keyLight.Index = 2

	local fillLight = {}
	fillLight.Angle = 360
	fillLight.Color = Color(209,235,246,255)
	fillLight.Radius = 100.0
	fillLight.Brightness = 10
	fillLight.Size = 100
	fillLight.Index = 3

	self:StoreLightData( BACKLIGHT_IDENT, backLight)
	self:StoreLightData( KEYLIGHT_IDENT, keyLight)
	self:StoreLightData( FILLLIGHT_IDENT, fillLight)

	self:SetModel( MODEL )
	self:PhysicsInitSphere( 8, "metal" )
	self:SetMoveType( MOVETYPE_VPHYSICS )
	self:SetSolid( SOLID_VPHYSICS )
	self:DrawShadow( false )
	
	local phys = self:GetPhysicsObject()
	
	if (phys:IsValid()) then
		phys:Wake()
	end
	
end


/*---------------------------------------------------------
   Name: Sets the color of the light
---------------------------------------------------------*/
function ENT:SetLightColor( r, g, b )

	self.Entity:SetVar( "lightr", r )
	self.Entity:SetVar( "lightg", g )
	self.Entity:SetVar( "lightb", b )
	
	self.Entity:SetColor( r, g, b, 255 )

end

/*---------------------------------------------------------
   Name: OnTakeDamage
---------------------------------------------------------*/
function ENT:OnTakeDamage( dmginfo )
	self.Entity:TakePhysicsDamage( dmginfo )
end

/*---------------------------------------------------------
   Name: Toggle
---------------------------------------------------------*/
function ENT:InvokeProperties(player)

	if( player && player:IsValid() && player:IsPlayer()) then

		local recipientFilter = RecipientFilter()
		recipientFilter:AddPlayer(player)
	
		umsg.Start("req_ShowProp", recipientFilter)
		umsg.Entity(self.Entity)
		umsg.End()

	end

end


/*---------------------------------------------------------
   Name: Toggle
---------------------------------------------------------*/
function ENT:Toggle()
	
end

/*---------------------------------------------------------
   Name: PhysicsUpdate
---------------------------------------------------------*/
function ENT:PhysicsUpdate(physobj)
	if not self.Entity:IsPlayerHolding() then
		if self.IsMapController then
			physobj:EnableMotion(false)
		else
			physobj:Sleep()
		end
	end
end